/*
 * @Author: 颜礼田 2564217790@qq.com
 * @Date: 2024-09-07 16:50:03
 * @LastEditors: MrDotYan 2564217790@qq.com
 * @LastEditTime: 2024-09-10 22:54:17
 * @FilePath: /webServer/src/model/role/role.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Column, Entity, JoinTable, ManyToMany } from 'typeorm';
import { DBColumns } from '../';
import {
  MenusSchema,
  PermissionSchema,
  RoleSchema,
  UserSchema,
} from '../../schema';
import { Permission } from '../permission/permission';
import { Menus } from '../menus/menus';
import { User } from '../user/user';

@Entity('role')
export class Role extends DBColumns implements RoleSchema {
  @Column({
    type: 'varchar',
    length: 50,
    nullable: false,
    default: null,
    comment: '角色编码',
  })
  roleCode: string;
  @Column({
    type: 'varchar',
    length: 50,
    nullable: false,
    default: null,
    comment: '角色名称',
  })
  roleName: string;

  @ManyToMany(() => Menus, menus => menus.role)
  @JoinTable({ name: 'role_menus' })
  menus: MenusSchema[];

  @ManyToMany(() => Permission, permission => permission.role)
  @JoinTable({ name: 'role_permission' })
  permission: PermissionSchema[];

  @ManyToMany(() => User, user => user.role)
  user?: UserSchema[];
}
